package br.uefs.dexa.rfframework.gui.interfaces;

import java.awt.Component;
import java.awt.Container;

import javax.swing.SwingUtilities;

import br.uefs.dexa.rfframework.gui.factory.GUIAbstractFactory;
import br.unicamp.ic.lis.rfframework.objects.IDigitalObject;

public abstract class RelevantObjectSetContainerPanel extends ObjectSetContainerPanel implements RelevanceFeedbackViewer {

	
	private static final long serialVersionUID = 1831669733278029888L;
	

	protected RelevantObjectSetContainerPanel(RFUserGUI gui)
	{
		super(gui);
		setupRFProcessingTriggerEvent();
	}
	
	@Override
	public void showObjectPanel(DigitalObjectPanel panel)
	{
		getRelevantObjectsContainer().add(panel);
		getRelevantObjectsContainer().revalidate();
		getRelevantObjectsContainer().repaint();
	}
	
	@Override
	public void removeObjectPanel(DigitalObjectPanel panel)
	{
		getRelevantObjectsContainer().remove(panel);
		getRelevantObjectsContainer().revalidate();
		getRelevantObjectsContainer().repaint();
	}
	
	@Override
	public  DigitalObjectPanel getDigitalObjectPanel(IDigitalObject object)
	{
		return GUIAbstractFactory.getInstance().getRelevantObjectPanel(object);
	}
	
	protected void relevanceFeedbackProcessingEvent()
	{
		RelevantObjectSetContainerPanel.super.getGUI().relevantObjectsSelected();
	}
	
	private void setupRFProcessingTriggerEvent()
	{
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				getRFProcessingTriggerComponent().addMouseListener(new java.awt.event.MouseAdapter() {
				    public void mouseClicked(java.awt.event.MouseEvent evt) {
				    	
				    	//RelevantObjectSetContainerPanel.super.getGUI().relevantObjectsSelected();
				    	relevanceFeedbackProcessingEvent();
				    }
				});
			}
		});
		
	}
	
	
	@Override
	public void beforeQuerySelection()
	{
		//empty
	}

	@Override
	public void querySelectionMode()
	{
		//empty
	}
	
	@Override
	public void afterQuerySelection()
	{
		//empty
	}
	
	@Override
	public void beforeRelevanceFeedback()
	{
		//empty
	}
	
	@Override
	public void relevanceFeedbackMode()
	{
		//empty
	}
	
	@Override
	public void afterRelevanceFeedback()
	{
		//empty
	}
	
	
	/*
	 * Returns the GUI component responsible for triggering the relevant objects processing.
	 * As an example, can simply return a JButton;
	 * Must be implemented on subclasses. 
	 */
	public abstract Component getRFProcessingTriggerComponent();
	
	/*
	 * Returns the GUI container responsible for keeping the relevant objects DigitalObjectPanels.
	 * As an example, can simply return a JPanel containing the relevant DigitalObjectPanels;
	 * Must be implemented on subclasses. 
	 */
	public abstract Container getRelevantObjectsContainer();
	
	

}
